<?php
/**
 * 作者: 王志昂-黑米<wangzhiangtony@qq.com>
 * 个人说明: 春水初涨，春林初盛，春风十里，不如你。
 * 创建时间: 2015-08-19 16:18
 * 说明:
 */
namespace Home\Service;
use \Think\Model;

class DeptService extends Model
{
    public function filterIssueByDept($dept, $res)
    {
        $sameDeptUserInfoArr = M('User')->where("deleted='0' and dept in (" . $dept . ")")->field('id')->select();
        $sameDeptUserIdArr = array();
        foreach ($sameDeptUserInfoArr as $key => $value) {
            $sameDeptUserIdArr[] = $value['id'];
        }
        foreach ($res as $key => $value) {
            if (in_array($value['developer_id'], $sameDeptUserIdArr)) {
                continue;
            }
            $developMembers = explode(',', $value['develop_members']);
            $developMembersIntersect = array_intersect($developMembers, $sameDeptUserIdArr);
            if (!empty($developMembersIntersect)) {
                continue;
            }
            unset($res[$key]);
        }
        return $res;
    }

    public function getSpecialUserDept($userId, $dept)
    {
        $specialUserDeptRes = M('SpecialUserDept')->where("is_deleted='N' and user_id=" . $userId)->select();
        if ($specialUserDeptRes) {
            $dept = $specialUserDeptRes[0]['dept'];
            if ($dept == 0) {
                $allDept = M('Dept')->select();
                $deptArr = array();
                foreach ($allDept as $key => $val) {
                    $deptArr[] = $val['id'];
                }
                $dept = implode(',', $deptArr);
            }
        }
        return $dept;
    }
}